﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DesignPatterns
{
    public interface IObserver
    {
        void Operate(IObSubject subject);
    }

    class ObserverA : IObserver
    {
        public void Operate(IObSubject subject)
        {
            Console.WriteLine("AAA 处理消息" + subject.Name);
        }
    }

    class ObserverB : IObserver
    {
        public void Operate(IObSubject subject)
        {
            Console.WriteLine("BBB 处理消息" + subject.Name);
        }
    }

    public interface IObSubject
    {
        string Name { get; }

        void Attach(IObserver observer);

        void Notify();
    }

    class ObSubject : IObSubject
    {
        List<IObserver> observers = new List<IObserver>();

        public string Name { get; set; }

        public void Attach(IObserver observer) => observers.Add(observer);

        public void Notify()
        {
            foreach (var item in observers)
            {
                item.Operate(this);
            }
        }

    }



    class ObserverPattern
    {
    }
}
